package com.tenbent.product.center.example.stu.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.tenbent.product.base.exception.TenbentException;
import com.tenbent.product.base.query.PageQuery;
import com.tenbent.product.base.query.page.PageResult;
import com.tenbent.product.base.query.page.Pageable;
import com.tenbent.product.base.service.impl.BaseServiceImpl;
import com.tenbent.product.center.example.stu.bo.Student;
import com.tenbent.product.center.example.stu.mapper.StudentMapper;
import com.tenbent.product.center.example.stu.service.StudentService;

/**
 * Created by ThinkPad on 2017/7/27.
 */
@Service(value = "studentServiceImpl")
public class StudentServiceImpl extends BaseServiceImpl<Student> implements StudentService {

	public StudentServiceImpl() {
		this.setClazz(Student.class);
	}

	@Autowired
	private StudentMapper studentMapper;

	@Override
	public List<Student> queryStuList(Student stu) throws TenbentException {
		return studentMapper.queryStuList(stu);
	}

	@Override
	public PageResult<Student> queryStuPage(Pageable pageable) throws TenbentException {
		return PageQuery.executeObjQuery(pageable,
				filter -> (Page<Student>) studentMapper.queryStuList((Student) pageable.getParamBizObject()));
	}

	@Override
	public PageResult<Map<String, Object>> queryStuPageMap(Pageable pageable) throws TenbentException {
		return PageQuery.executeMapQuery(pageable,
				filter -> (Page<Map<String, Object>>) studentMapper.queryStuListMap(pageable.getParamMap()));
	}

	@Override
	public Student saveStu(Student stu) throws TenbentException {
		studentMapper.saveStu(stu);
		return stu;
	}

	@Override
	public Student updateStu(Student stu) throws TenbentException {
		studentMapper.updateStu(stu);
		return stu;
	}

	@Override
	public Student findOne(Integer id) throws TenbentException {
		return studentMapper.findOne(id);
	}

	@Override
	public void removeStu(Integer id) throws TenbentException {
		studentMapper.removeStu(id);
	}
}
